to get groupReplace groupID,textToReplace,replaceText
step i from 1 to itemCount(objects of groupID)
if script of item i of objects of groupID contains textToReplace
step n from 1 to wordCount(script of item i of objects of groupID)
if word n of script of item i of objects of groupID = textToReplace as text
put replaceText into word n of script of item i of objects \
of groupID
end if
end step
end if
if object of item i of objects of groupID is group
get groupReplace(item i of objects of groupID,textToReplace, \
replaceText)
end if
end step
return true
end groupReplace
}
SCRIPT "Unpack a DWord to three bytes"
BEHAVIOR "Takes a DWord and unpacks it into three bytes. Useful for getting colors and MIDI messages from Windows. "
CATEGORY Utilities
{
to get explicitByte packedDWord
r = (packeddword mod 256)
g = (packeddword mod 65536) bitShiftRight 8
b = packeddword bitShiftRight 16
push b onto it
push g onto it
push r onto it
return it
end explicitByte
}
SCRIPT "Pack three bytes into a DWord"
BEHAVIOR "Takes three bytes and packs them into a DWord. Useful for sending colors and MIDI messages to Windows. "
CATEGORY Utilities
{
to get packDWord rgb
set r to item 1 of rgb
set g to item 2 of rgb
set b to item 3 of rgb
set it to r + (g bitShiftLeft 8) + (b bitshiftLeft 16)
return it
end packDWord
}
ACTION "Create a link to timeGetTime()"
BEHAVIOR "Create a link to timeGetTime() for timing events. This is a better timer than getTickCount. "
CATEGORY Windows
{
linkdll "mmSystem"
DWORD timeGetTime()
end
}
ACTION "Flash screen"
BEHAVIOR "Causes the ToolBook window to flash $$times times at a rate of approx. $$speed flashes per second. "
CATEGORY Effects
ARG times IS "5" help "Can be any number of times."
ARG speed ONEOF "1000,500,100" IS "100" help "the faster it flashes."
{
--to handle flash -- suggested custom message
linkDLL "kernel"
word globalAlloc(word,dword)
pointer globalLock(word)
word globalUnlock(word)
word globalFree(word)
end linkDLL
linkDLL "user"
word invertRect(word,pointer)
word getClientRect(word,pointer)
word getDC(word)
int releaseDC(word,word)
end linkDLL
set vHmem to globalAlloc(66, 8)
set vPtrMem to globalLock(vHmem)
get getClientRect(sysClientHandle,vPtrMem)
set vHDC to getDC(sysClientHandle)
set newSpeed to 1000/$$speed
step i from 1 to $$times
get invertRect(vHDC,vPtrMem)
pause newSpeed ticks
get invertRect(vHDC,vPtrMem)
pause newSpeed ticks
end step
get releaseDC (sysClientHandle,vHDC)
get GlobalUnlock(vHmem)
get GlobalFree(vHmem)
unlinkDLL "kernel"
unlinkDLL "user"
--end
}
SCRIPT "Find the execution time"
BEHAVIOR "Use these two handlers to make timing tests. They will automatically compare two tests run in a row. "
CATEGORY Debug
{
to handle startTime
system s_testTime
linkDLL "mmSystem"
DWORD timeGetTime()
end linkDLL
set s_testTime to timeGetTime()
end startTime
to handle showElapsedTime
system s_testTime, s_lastTestTime
set thisTestTime to (timeGetTime() - s_testTime) / 1000
format number thisTestTime as "#.0"
set prompt to "This test took" && thisTestTime && "seconds."
if s_lastTestTime <> 0 and s_lastTestTime is not null
get (thisTestTime - s_lastTestTime)
set deltaTime to (it / min(s_lastTestTime,thisTestTime)) * 100
format number deltaTime as "#.0"
if deltaTime <> 0
conditions
when deltaTime < 0
set relation to "faster"
when deltaTime > 0
set relation to "slower"
end conditions
get abs(deltaTime)
format number it as "#.0"
put " It was" && it & "%" && relation &&\
"than the previous test." after prompt
end if
end if
request prompt
set s_lastTestTime to thisTestTime
unlinkDLL "mmSystem" -- decrement refCount
end showElapsedTime
}
SCRIPT "Initialize a conversation with Excel"
BEHAVIOR "This function will run Excel if it is not running already. If a filename is passed to this function it will tell Excel to load that file if it is not loaded already. "
BEHAVIOR "Returns information on the capabilities of the multimedia drivers "
CATEGORY Multimedia
ARG mediaType ONEOF "all,animation,bitmap,cdAudio,digitalVideo,overlay,sequencer,vcr,videodisc,waveAudio" IS "all" help "Choose a device type."
ARG info ONEOF "can eject,can freeze,can play,can record,can reverse,can save,can stretch,compound device,device type,fast play rate,has audio,has video,inputs,normal play rate,outputs,slow play rate,uses files,uses palettes,windows" IS "device type" help "Get this information about the device."
{
-- If the behavior is not supported by the driver, but is supported
-- in the spec, this function will return FALSE. If the behavior is
-- not supported in the spec, this will return NULL and set up
-- a report that is shown if sysMediaSuspend is TRUE
sMS = sysMediaSuspend
sysMediaSuspend = FALSE
clear sysError
devType = "$$mediaType"
cap = "$$info"
get callMCI("capability" && devType && cap)
if sysError is NULL
request it
else
if sMS = TRUE -- we'll trap the error if the user is expecting it
BEHAVIOR "Sets the volume for the virtual audio mixer "
CATEGORY Multimedia
ARG lineType ONEOF "device_in,device_out" IS "device_in" help "Choose input or output"
ARG lineSpec ONEOF "AMP,AUX,CDA,MIC,MUS,WAV" IS "WAV" help "Choose the MCI device to query"
ARG channel ONEOF "LEFT,RIGHT,BOTH" IS "BOTH" help "Choose which channel"
ARG value ONEOF "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100" IS "99" help "Choose the percent of full volume"
{
-- The virtual mixer does the best it can with whatever
-- soundcard is on the target machine. As there is no real
-- standard, results will vary from card to card.
clear sysError
get mixerCommand("set tbkmixer $$lineType $$lineSpec control volume $$channel value")
if it = 0
if $$channel <> "both"
request "Volume for the $$channel channel of the $$lineSpec device has been set to $$value"
else
request "Volume for both channels of the $$lineSpec device have been set to $$value"
end if
else
request sysError
end if
}
ACTION "Let user set mixer values for a device"
BEHAVIOR "Lets the user set the volume for the virtual audio mixer "
CATEGORY Multimedia
ARG lineType ONEOF "device_in,device_out" IS "device_in" help "Choose input or output"
ARG lineSpec ONEOF "AMP,AUX,CDA,MIC,MUS,WAV" IS "WAV" help "Choose the MCI device to query"
{
-- The virtual mixer does the best it can with whatever
-- soundcard is on the target machine. As there is no real
-- standard, results will vary from card to card.
-- This script lets the author decide which device,
-- but lets the user decide what value
local l_cancel,l_channel,l_value
request "What channel would you like to set the volume of: the left, right, or both channels?" \
with "Left" or "Right" or "Both"
if it <> null -- null when canceled with the system button or alt-F4
set l_channel to it
else
set l_cancel to TRUE,"the user canceled."
end if
if item 1 of l_cancel <> TRUE
ask "What percent of full volume should the setting be?" with "50"
if isType(INT,it) and it >= 0 and it <=100
set l_value to it
else
set l_cancel to TRUE,"there was a bad value for volume."
end if
end if
clear sysError
if item 1 of l_cancel <> TRUE
get mixerCommand("set tbkmixer $$lineType $$lineSpec control volume" && l_channel && l_value)
if it = 0
if l_channel <> "both"
request "Volume for the" && l_channel && "channel of the $$lineSpec device has been set to" && l_value
else
request "Volume for both channels of the $$lineSpec device have been set to" && l_value
end if
else
request sysError
end if
else
request "The command was not executed because" && item 2 of l_cancel
end if
}
ACTION "Get mixer values"
BEHAVIOR "Gets the volume for the virtual audio mixer "
CATEGORY Multimedia
ARG lineType ONEOF "device_in,device_out" IS "device_in" help "Choose input or output"
ARG lineSpec ONEOF "AMP,AUX,CDA,MIC,MUS,WAV" IS "WAV" help "Choose the MCI device to query"
ARG channel ONEOF "LEFT,RIGHT,BOTH" IS "BOTH" help "Choose which channel"
{
-- The virtual mixer does the best it can with whatever
-- soundcard is on the target machine. As there is no real
-- standard, results will vary from card to card.
clear sysError
get mixerCommand("get tbkmixer $$lineType $$lineSpec control volume $$channel")
if sysError is NULL
if $$channel <> "both"
request "Volume for the $$channel channel of the $$lineSpec device is set to" && it
else
request "Volume for both channels of the $$lineSpec device are set to" && it
end if
else
request sysError
end if
}
ACTION "Image Command - Capability"
BEHAVIOR "Requests information about the capability of the bitmap player "
CATEGORY Images
ARG args ONEOF "compound device,device type,has files,has video,static,uses palettes" IS "device type" help "Choose what capability."
{
get imageCommand("capability placeHolder $$args")
request it
}
ACTION "Image Command - Close"
BEHAVIOR "Closes the window and file associated with the alias "
CATEGORY Images
ARG alias IS "myAlias" help "The filename or the alias you want to close or ALL to close all open bitmaps. Keep your aliases consistent!"
{
get imageCommand("close $$alias")
}
ACTION "Image Command - Info"
BEHAVIOR "Get info on the window or file associated with the alias "
CATEGORY Images
ARG alias IS "myAlias" help "The filename or the alias you want information on. Keep your aliases consistent!"
ARG args ONEOF "product,text,file" IS "file" help "The type of information you want."
{
get imageCommand("info $$alias $$args")
request it
}
ACTION "Image Command - Open"
BEHAVIOR "Initializes the displayer and associates the file with the alias "
CATEGORY Images
ARG myBitmap FILE "Bitmap Files(*.BMP),*.bmp,(*.DIB),*.dib" IS "Cars.bmp" help "Find the bitmap file to display."
ARG alias IS "myAlias" help "The alias you want associated with this file. Keep your aliases consistent!"
ARG style ONEOF "overlapped,popup,child" IS "overlapped" help "Choose the style of the window."
{
get imageCommand("open $$myBitmap alias $$alias style $$style")
}
ACTION "Image Command - Play"
BEHAVIOR "Play the file in the window associated with the alias "
CATEGORY Images
ARG alias IS "myAlias" help "The filename or the alias you want to play. Keep your aliases consistent!"
{
get imageCommand("play $$alias")
}
ACTION "Image Command - Put"
BEHAVIOR "Play the file in the window associated with the alias "
CATEGORY Images
ARG alias IS "myAlias" help "The filename or the alias you want to play. Keep your aliases consistent!"
ARG whereTo ONEOF "source,destination" IS "destination" help "Get the offset and extent of the source or destination."
ARG x1 IS "0" help "Left to right offset."
ARG y1 IS "0" help "Up to down offset."
ARG x2 IS "100" help "Left to right extent."
ARG y2 IS "100" help "Up to down extent."
{
get imageCommand("put $$alias $$whereTo at $$x1 $$y1 $$x2 $$y2")
}
ACTION "Image Command - Status"
BEHAVIOR "Get the status of the window and file associated with the alias "
CATEGORY Images
ARG alias IS "myAlias" help "The filename or the alias you want the status of. Keep your aliases consistent!"
ARG args ONEOF "window,position,extent,size,visible,style,palette" IS "position" help "The element you need the status of."
{
get imageCommand("status $$alias $$args")
request it
}
ACTION "Image Command - Where"
BEHAVIOR "Obtains the rectangle specifying the source or destination area of the image. "
CATEGORY Images
ARG whereTo ONEOF "source,destination" IS "destination" help "Get the offset and extent of the source or destination."
ARG alias IS "myAlias" help "The filename or the alias you want. Keep your aliases consistent!"
{
get imageCommand("where $$alias $$whereto")
request it
}
ACTION "Image Command - Window"
BEHAVIOR "Change parameters of the window associated with the alias "
CATEGORY Images
ARG alias IS "myAlias" help "The filename or the alias you want to close or ALL to close all open bitmaps. Keep your aliases consistent!"
ARG args ONEOF "text,position,size" IS "position" help "Choose what aspect of the window to change."
ARG value IS "myValue" help "For 'text' the caption of the window or use 'default' for the name of the bitmap. For 'position'and 'size' use two pixels e.g. '100"
{
get imageCommand("window $$alias $$args $$value")
}
ACTION "Image Command - Window State"
BEHAVIOR "Change the state of the window associated with the alias "
CATEGORY Images
ARG alias IS "myAlias" help "The filename or the alias you want to close or ALL to close all open bitmaps. Keep your aliases consistent!"
ARG value ONEOF "hide,minimize,minimized,show,maximize,iconic,asIs,asWas,normal" IS "show" help "Use one of these constants to more precisely control the way the window is displayed."
{
get imageCommand("window $$alias state $$value")
}
ACTION "Play a Wave file as a new clip"
BEHAVIOR "Creates a clip from a wave file using 'WaveFile' ($$WaveFile,) then plays it. "
CATEGORIES Clips,Audio
ARG waveFile FILE "Wave Files(*.WAV),*.wav" IS "Chord.Wav" help "Get the wave file."
ARG clipName IS "myClip" help "Give the new clip a name."
ARG startTime IS "0:00:00" help "Set to a time in 'Minutes:Seconds:Milliseconds' format; defaults to beginning of the file."
ARG endTime IS "0:10:00" help "Set to a time in 'Minutes:Seconds:Milliseconds' format; defaults to 10 seconds into the file."
{
-- The new clip is made when this script is activated,
-- not when it is written, so make sure the media is
-- still in the right place before activating this script
new clip from "$$WaveFile"
name of it = "$$clipName"
mediaRef = clip "$$clipName"
mmTimeFormat of mediaRef = "MSms"
mmBeginPoint of mediaRef = "$$startTime"
mmEndPoint of mediaRef = "$$endTime"
mmPlay mediaRef autoclose
}
ACTION "Play an AVI file as a clip"
BEHAVIOR "Creates a clip from an AVI file using 'AVIFile' ($$AVIFile,) then plays it. "
CATEGORIES Clips,Video
ARG AVIFile FILE "AVI Files(*.avi),*.avi" IS "windmill.avi" help "Get the wave file."
ARG clipName IS "myClip" help "Give the new clip a name."
ARG startTime IS "0" help "Set to frame number; defaults to beginning of the file."
ARG endTime IS "300" help "Set to a frame number; defaults to frame 300."
ARG StageObj OBJTYP "Stage" IS "stage myStage" help "Choose the stage object for playback"
{
-- The new clip is made when this script is activated,
-- not when it is written, so make sure the media is
-- still in the right place before activating this script
new clip from "$$AVIFile"
name of it = "$$clipName"
mediaRef = clip "$$clipName"
mmTimeFormat of mediaRef = "frames"
mmBeginPoint of mediaRef = "$$startTime"
mmEndPoint of mediaRef = "$$endTime"
mmPlay mediaRef in $$StageObj autoclose
}
ACTION "Build and play an AVI clip w/out the clip manager"
BEHAVIOR "Allows the user to create a clip from an AVI file then plays it."
CATEGORY Clips,Video
ARG ClipName is "Enter a name for the new clip" help "This is the default text the user will see or modify for your needs."
ARG StageObj OBJTYP "Stage" is "stage myStage" help "Choose the stage object for playback"
ARG BeginPoint is "Enter a beginning point for the clip in frames" help "This is the default text the user will see or modify for your needs."
ARG EndPoint is "Enter an ending point for the clip in frames" help "This is the default text the user will see or modify for your needs."
ARG caption is "Open an AVI File" help "This is the default text the user will see or modify for your needs."
ARG prompt is "Choose the AVI file to open" help "This is the default text the user will see or modify for your needs."
{
-- The new clip is made by the user, so this is more
-- flexible than the 'Play a Wave file as a clip' script.
-- This is a good sample script, as defauults and errorrs
-- are handled fairly gracefully.
while not (sysSupportedMedia contains "digitalVideo")
request "Error: breaking execution of this script." & CRLF \
& "Multimedia ToolBook is not being allowed to play digitalVideo." & CRLF \
& "The appropriate drivers may not be available."
break to system
end while
linkDll sysToolBookDirectory & "tb40dlg.dll"
string openDlg(string,string,string,string)
end linkDLL
get openDlg(".","*.avi","$$prompt","$$caption")
if it <> null
newAVI = it
do
ask "$$ClipName" with "newClip"
if it is null
request "Are you sure you want to cancel creating this clip?" \
with "Yes, cancel" or "No, try again"
if it contains "Yes"
break to system
else
clear it
end if
end if
until it <> null
clipName = it
new clip from newAVI
name of it = clipName
mediaRef = clip clipName
while not (mmPlayable of mediaRef)
request "This clip is not playable"
break to system
end while
mmTimeFormat of mediaRef = "frames"
sS = sysSuspend
sMS = sysMediaSuspend
sysSuspend = FALSE
sysMediaSuspend = FALSE
ask "$$BeginPoint" with "0"
clear sysError
mmBeginPoint of mediaRef = it
if sysError <> null
request "Error, the beginning point of the clip set to default: ""0"""
mmBeginPoint of mediaRef = "0"
end if
ask "$$EndPoint" with "300"
clear sysError
mmEndPoint of mediaRef = it
if sysError <> null
request "Error, the ending point of the clip set to default: ""300"""
mmEndPoint of mediaRef = "300"
end if
sysSuspend = sS
sysMediaSuspend = sMS
if mmPlayable of mediaRef
mmPlay mediaRef in $$StageObj autoclose
end if
end if
unlinkDLL sysToolBookDirectory & "tb40dlg.dll"
}
ACTION "Build and play a Wave clip"
BEHAVIOR "Allows the user to create a clip from a wave file then plays it."
CATEGORY Clips,Audio
ARG ClipName is "Enter a name for the new clip" help "Default is good or modify for your needs."
ARG BeginPoint is "Enter a beginning point for the clip in 'Minutes:Seconds:Milliseconds'" help "Default is good or modify for your needs."
ARG EndPoint is "Enter an ending point for the clip in 'Minutes:Seconds:Milliseconds'" help "Default is good or modify for your needs."
ARG caption is "Open a Wave File" help "Default is good or modify for your needs."
ARG prompt is "Choose the wave file to open" help "Default is good or modify for your needs."
{
-- The new clip is made by the user, so this is more
-- flexible than the 'Play a Wave file as a clip' script.
-- This is a good sample script, as defauults and errorrs
-- are handled fairly gracefully.
-- this funny structure gets around auto-script choking when it sees the break
-- statement in an "if" structure
while not (sysSupportedMedia contains "waveAudio")
request "Error: breaking execution of this script." & CRLF \
& "The multimedia driver can not find the waveAudio device." & CRLF \
& "The appropriate drivers may not be available."
break to system
end while
linkDll sysToolBookDirectory & "tb40dlg.dll"
string openDlg(string,string,string,string)
end linkDLL
get openDlg(".","*.wav","$$prompt","$$caption")
if it <> null
newWave = it
do
ask "$$ClipName" with "newClip"
if it is null
request "Are you sure you want to cancel creating this clip?" \
with "Yes, cancel" or "No, try again"
if it contains "Yes"
break to system
else
clear it
end if
end if
until it <> null
clipName = it
new clip from newWave
name of it = clipName
mediaRef = clip clipName
mmTimeFormat of mediaRef = "MSms"
sS = sysSuspend
sMS = sysMediaSuspend
sysSuspend = FALSE
sysMediaSuspend = FALSE
ask "$$BeginPoint" with "0:00:00"
clear sysError
mmBeginPoint of mediaRef = it
if sysError <> null
request "Error, the beginning point of the clip set to default: ""0:00:00"""
mmBeginPoint of mediaRef = "0:00:00"
end if
ask "$$EndPoint" with "0:05:00"
clear sysError
mmEndPoint of mediaRef = it
if sysError <> null
request "Error, the ending point of the clip set to default: ""0:05:00"""
mmEndPoint of mediaRef = "0:05:00"
end if
sysSuspend = sS
sysMediaSuspend = sMS
if mmPlayable of mediaRef
mmPlay mediaRef autoclose
end if
end if
unlinkDLL sysToolBookDirectory & "tb40dlg.dll"
}
ACTION "Set book to read automatically"
BEHAVIOR "Example program for a continuously running book. "